import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class InitUser {
	
	ArrayList<User> userList = new ArrayList<User>();
	public InitUser() throws IOException{
		
		readFromFile();
	}
	
	
	public void readFromFile() throws IOException{
		
	    FileReader fr = new FileReader("user.txt");
	    BufferedReader br = new BufferedReader(fr);
	    
	    String zeile = "";
	    String[] array;

	    try {
			while( (zeile = br.readLine()) != null )
			{
				array = zeile.split(";");
				userList.add(new User(array[0], array[1], array[2]));
			}
		} catch (IOException e) {
			System.out.println("Kein File");
			e.printStackTrace();
		}
	    finally{
	    	br.close();
	    }
	}
	//Berechtigung testen
	public void checkUser(String mail){
		
		Pattern pattern = Pattern.compile("<(.*?)>");
		Matcher matcher = pattern.matcher(mail);
		if(matcher.find()){
		mail = matcher.group(1);
		}
		for(User i : userList){
			
			if(mail.equals(i.getMail())){
				
				System.out.println(i.getName()+" "+i.getPass()+" "+mail);
			}
			else{
				
				System.out.println("Standard");
			}
		}
	}
	
	
	

}
